

#ifndef __COMM_MSG_TASK_CTRL_H__
#define __COMM_MSG_TASK_CTRL_H__

#include "comm/comm_topic_name.h"
#include "comm/comm_base.h"
#include <comm_msg/task_ctrl.h>
#include <ros/ros.h>
#include <iostream>
#include <list>
#include <vector>

using namespace std;

/**************************************************************************************
功能描述: 自动任务控制类型
修改记录:
**************************************************************************************/
typedef enum {
    TASK_CTRL_TYPE_START            = 0,        /* 启动任务 */
    TASK_CTRL_TYPE_STOP             = 1,        /* 停止任务 */
    TASK_CTRL_TYPE_SUSPEND          = 2,        /* 挂起任务 */
    TASK_CTRL_TYPE_RESUME           = 3,        /* 恢复挂起任务 */
    TASK_CTRL_TYPE_SET_CLEAN_STATE  = 4,        /* 设置清扫状态 */
} TASK_CTRL_TYPE_ENM;

/**************************************************************************************
功能描述: 发布任务控制消息
修改记录:
**************************************************************************************/
class TSK_CTRL_SENDER_C
{
public:
    TSK_CTRL_SENDER_C(ros::NodeHandle &nh)
    {
        publisher_ = nh.advertise<comm_msg::task_ctrl>(TOPIC_NAME_TASK_CTRL, 10);
    }

    void Start(UINT32 routeNo, BOOL isClean)
    {
        SendMsg(TASK_CTRL_TYPE_START, routeNo, isClean);
    }

    void Stop(void)
    {
        /* 停止任务时，路径号和清扫控制无效 */
        SendMsg(TASK_CTRL_TYPE_STOP, UINT32_NULL, false);
    }

    void Suspend(void)
    {
        /* 挂起任务时，路径号和清扫控制无效 */
        SendMsg(TASK_CTRL_TYPE_SUSPEND, UINT32_NULL, false);
    }

    void Resume(void)
    {
        /* 恢复任务时，路径号和清扫控制无效 */
        SendMsg(TASK_CTRL_TYPE_RESUME, UINT32_NULL, false);
    }

    void SetPatrol(void)
    {
        /* 设置巡逻时，路径号无效 */
        SendMsg(TASK_CTRL_TYPE_SET_CLEAN_STATE, UINT32_NULL, false);
    }

private:
    ros::Publisher publisher_;

    void SendMsg(TASK_CTRL_TYPE_ENM enTaskCtrlType, UINT32 routeNo, BOOL isClean)
    {
        comm_msg::task_ctrl stMsg;

        stMsg.ctrlType = (UINT08)enTaskCtrlType;
        stMsg.routeNo  = routeNo;
        stMsg.isClean  = (UINT08)isClean;

        publisher_.publish(stMsg);
        ST_LOG_INFO("(start %u, stop %u, suspend %u, resume %u, setclean %u) Tsk Ctrl Type(%u), RouteNo=%u, isClean=%u. ", 
                    TASK_CTRL_TYPE_START, 
                    TASK_CTRL_TYPE_STOP,
                    TASK_CTRL_TYPE_SUSPEND,
                    TASK_CTRL_TYPE_RESUME,
                    TASK_CTRL_TYPE_SET_CLEAN_STATE,
                    stMsg.ctrlType, 
                    stMsg.routeNo, 
                    isClean);
    }
};


#endif

